/**
  ******************************************************************************
  * File Name          : motor.h
  * Description        : 电机控制代码的对外接口，比如设置速度等
  ******************************************************************************
  */
#ifndef __MOTOR_H__
#define __MOTOR_H__

#include "stm32f4xx_hal.h"
#include "pid.h"

typedef struct __Motor_bsp_t
{
	CAN_HandleTypeDef* hcan;
	uint8_t can_id;
	
	int16_t angle;
	int16_t speed;
	int16_t current;
	int8_t  temp;
	
	int16_t turns;
	int16_t last_angle;
	
	float abs_angle_offset;
	float encoder_angle_offset;
	float abs_angle_fdb;
} Motor_bsp_t;

typedef enum __Motor_Ctrl_Mode
{
	MOTOR_CTRL_OPENLOOP,
	MOTOR_CTRL_SPEED,
	MOTOR_CTRL_POS
} Motor_CtrlMode;

typedef struct __Motor_t
{
	Motor_bsp_t bsp;
	PID_Regulator_t spd_pid;
	PID_Regulator_t pos_pid;
	Motor_CtrlMode ctrl_mode;

} Motor_t;

void Motor_SetCtrlMode(Motor_t *motor, Motor_CtrlMode mode);
void Motor_Ctrl_Calc(Motor_t *motor);
void Motor_SetPwr(Motor_t *motor, float pwr);
void Motor_SetSpd(Motor_t *motor, float spd);
void Motor_SetPos(Motor_t *motor, float pos);


#endif /*__MOTOR_H__ */
